package io.day03;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FinallyDemo3 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.dat");
            fos.write(1);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(fos!= null){
                    fos.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            fos = new FileOutputStream("das.dat");
            fos.write("fdsa".getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        FileOutputStream fos2 =null;
        try {
            fos2 = new FileOutputStream("fdjsa.txt");
            fos2 .write(123);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos2.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
